<template>
	<view class="options">
		<picker mode="selector" :range="types" range-key="title" @change="changeType">
			<view class="opts-type">
				<view class="opt-text">{{types[typeCurrent].title}}</view>
				<image class="icon32" src="" mode=""></image>
			</view>
		</picker>
		
		<view class="opts-time">
			<picker mode="date" @change="changeTimeStart">
				<view class="time-range" :class="{'ft-gray':!timerange[0]}">{{timerange[0]||'选择开始时间'}}</view>
			</picker>
			—
			<picker mode="date" @change="changeTimeEnd">
				<view class="time-range" :class="{'ft-gray':!timerange[1]}">{{timerange[1]||'选择结束时间'}}</view>
			</picker>

			<view class="time-reset" @click="resetTime">重置</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				types:[{
					title:'全部订单',
					value:'0'
				}],
				typeCurrent: 0,
				timerange: []
			}
		},
		methods: {
			changeType(e){
				this.typeCurrent = e.detail.value;
				this.updateValue();
			},
			changeTimeStart(e) {
				this.timerange[0] = e.detail.value;
				this.updateValue();
				this.$forceUpdate();
			},
			changeTimeEnd(e) {
				this.timerange[1] = e.detail.value;
				this.updateValue();
				this.$forceUpdate()
			},
			resetTime(){
				this.timerange = []
				this.updateValue();
			},
			updateValue(){
				this.$emit('change',{
					type:this.types[this.typeCurrent].value,
					startTime:this.timerange[0],
					endTime:this.timerange[1]
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	%value-box {
		padding: 20rpx;
		height: 80rpx;
		background: #EEEEEE;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
	}

	view {
		box-sizing: border-box;
	}

	.ft {
		font-size: 28rpx;
		color: #222222;
		line-height: 33rpx;
	}

	.ft-gray {
		@extend .ft;
		color: #999999 !important;
	}


	.options {
		width: 750rpx;
		height: 240rpx;
		background: #FFFFFF;
		padding: 24rpx;

		.opts-type {
			@extend %value-box;
			width: 702rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.opt-text {
				@extend .ft;
			}
		}

		.icon32 {
			width: 32rpx;
			height: 32rpx;
		}

	}
</style>